package com.lams.action.comp;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.lams.action.SubAction;
import com.lams.service.comp.IAutoCompleteFacade;
import com.lams.util.ResultEntity;

public class AutoCompleteAction extends SubAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = -4984840794286595689L;
	
	private String sqlCode;
	
	private String query;
	
	private IAutoCompleteFacade acf;
	public IAutoCompleteFacade getAcf() {
		return acf;
	}

	public void setAcf(IAutoCompleteFacade acf) {
		this.acf = acf;
	}

	public String getSqlCode() {
		return sqlCode;
	}

	public void setSqlCode(String sqlCode) {
		this.sqlCode = sqlCode;
	}

	public String getQuery() {
		return query;
	}

	public void setQuery(String query) {
		this.query = query;
	}
	
	@SuppressWarnings("unchecked")
	public String execute(){
		Map params = new HashMap();
		params.put("sqlCode", sqlCode);
		params.put("query", query);
		params.put("start", this.getStart());
		params.put("limit", this.getLimit());
		Map map = acf.queryData(params);
		ResultEntity result = new ResultEntity();
		result.setData((List)map.get("data"));
		result.setTotalCount(Integer.parseInt(String.valueOf(map.get("totalCount"))));
		result.setSuccess(true);
		this.setResult(ResultEntity.decode(result));
		return SUCCESS;
	}
}
